<div class="febs-container" id="febs-peccancyClause-common">
    <div class="febs-component-body">
        <div class="layui-row febs-full layui-col-space8">
            <div class="layui-col-md4 layui-col-sm12 layui-col-xs12 febs-full">
                <div class="layui-card febs-full">
                    <div class="layui-card-body">
                        <form class="layui-form layui-table-form" lay-filter="peccancyClause-table-form" id="peccancyClause-table-form">
                            <div class="layui-form-item">
                                <label class="layui-form-label layui-form-label-sm" style="width:auto;">条款类型名称</label>
                                <div class="layui-input-block layui-input-icon-container" style=" margin-left: 115px;">
                                    <input type="text" name="clauseName" autocomplete="off" class="layui-input">
                                    <div class="layui-input-suffix"  id="queryPeccancyClauseCommon">
                                        <em class="layui-icon layui-icon-search"></em>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <table lay-filter="peccancyClauseCommonTable" id="peccancyClauseCommonTable"
                               lay-data="{id: 'peccancyClauseCommonTable'}"></table>
                    </div>
                </div>
            </div>
            <div class="layui-col-md8 layui-col-sm12 layui-col-xs12 febs-full">
                <div class="layui-card febs-full">
                    <div class="layui-card-body">
                        <form class="layui-form layui-table-form" lay-filter="peccancyClauseRule-table-form" id="peccancyClauseRule-table-form">
                            <div class="layui-form-item">
                                <label class="layui-form-label layui-form-label-sm" style="width: auto">条款编号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="clauseNo" autocomplete="off" class="layui-input">
                                </div>
                                <div id="queryPeccancyClauseRileCommon" class="layui-btn">
                                    <em class="layui-icon">&#xe615;</em> 查询
                                </div>
                            </div>
                        </form>
                        <table lay-filter="peccancyClauseRuleCommonTable" id="peccancyClauseRuleCommonTable"
                               lay-data="{id: 'peccancyClauseRuleCommonTable'}"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script data-th-inline="javascript">
    var disposeFormList = [[${disposeFormList}]];
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'commonJS', 'form', 'table', 'febs'], function () {

        var $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            commonJS = layui.commonJS,
            table = layui.table,
            $view = $('#febs-peccancyClause-common'),
            $queryPeccancyClauseCommon = $view.find('#queryPeccancyClauseCommon'),
            $queryPeccancyClauseRileCommon = $view.find('#queryPeccancyClauseRileCommon'),
            $peccancyClauseTableForm = $view.find('#peccancyClause-table-form'),
            $peccancyClauseRuleTableForm = $view.find('#peccancyClauseRule-table-form'),
            tableIns, tableInsRule
        ;


        let tenantId = POPUP_DATA.tenantId
        let clauseId = POPUP_DATA.clauseId
        let clauseRuleId = POPUP_DATA.clauseRuleId
        let selectList = POPUP_DATA.selectList
        let useScope = POPUP_DATA.useScope
        let clauseName = null
        form.render();

        initTable()

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('#peccancyClauseCommonTable'),
                id: 'peccancyClauseCommonTable',
                height: 'full',
                skin: '',
                cols: [[
                    {title: '序号', type: 'numbers', width: 60},
                    {field: 'clauseName', title: '条款类型名称', minWidth: 180},
                ]],
                done: function (res, curr, count) {
                    $view.find(".layui-table-view[lay-table-id='peccancyClauseCommonTable'] .layui-table-body.layui-table-main tr[data-index=0]").click();
                }
            });
            tableIns.reload({url: ctx + 'common/peccancyClause/list', where: getQueryParams(), page: {curr: 1}});
        }

        function initTableRule() {
            tableInsRule = febs.table.init({
                elem: $view.find('#peccancyClauseRuleCommonTable'),
                id: 'peccancyClauseRuleCommonTable',
                height: 'full',
                skin: '',
                cols: [[
                    {title: '', type: 'radio', width: 60},
                    {field: 'clauseNo', title: '条款编号', width: 160},
                    // {
                    //     field: 'clauseType', title: '奖惩类型', width: 100, align: 'center', templet: function (d) {
                    //         if (d.clauseType == '1') {
                    //             return '<span class="layui-badge febs-tag-green">奖</span>';
                    //         } else {
                    //             return '<span class="layui-badge febs-tag-red">惩</span>';
                    //         }
                    //     }
                    // },
                    {field: 'disposeForm', title: '处理形式', width: 160, align: 'center',templet:function (d){
                            if(d.disposeForm){
                                return febs.getDictLabel(disposeFormList,d.disposeForm);
                            }
                        }
                    },
                    {field: 'clauseContent', title: '条款内容', minWidth: 180},
                    {field: 'executeDate', title: '执行时间', width: 140, align: 'center'},
                ]]
            });
            tableInsRule.reload({url: ctx + 'common/peccancyClauseRule/list', where: getQueryRuleParams(), page: {curr: 1}});
        }

        table.on('row(peccancyClauseCommonTable)', function (obj) {
            obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
            clauseId = obj.data.clauseId
            clauseName = obj.data.clauseName
            initTableRule()
        });


        $queryPeccancyClauseCommon.on('click', function () {
            tableIns.reload({where: getQueryParams(), page: {curr: 1}});
        });

        $queryPeccancyClauseRileCommon.on('click', function () {
            tableInsRule.reload({where: getQueryRuleParams(), page: {curr: 1}});
        });

        window.getSelectData = function () {
            let selData = table.checkStatus("userTable")
            let returnData
            if (selData.data.length > 0) {
                if (!commonDto.multiple) {
                    returnData = selData.data[0]
                } else {
                    returnData = selData.data
                }

            }
            return returnData
        }


        function getQueryParams() {
            return  {
                tenantId:tenantId,
                clauseName:$peccancyClauseTableForm.find("input[name='clauseName']").val(),
                status: '1',
                useScope: useScope,
                invalidate_ie_cache: new Date()
            }
        }

        function getQueryRuleParams() {
            return  {
                tenantId:tenantId,
                clauseId:clauseId,
                clauseNo:$peccancyClauseRuleTableForm.find("input[name='clauseNo']").val(),
                status: '1',
                invalidate_ie_cache: new Date()
            }
        }

        window.getSelectData = function () {
            let selData = table.checkStatus("peccancyClauseRuleCommonTable")
            let returnData
            if (selData.data.length > 0) {
                returnData = {
                    tenantId: selData.data[0].tenantId,
                    clauseId: selData.data[0].clauseId,
                    clauseRuleId: selData.data[0].clauseRuleId,
                    clauseNo: selData.data[0].clauseNo,
                    clauseContent: selData.data[0].clauseContent,
                    // clauseType: selData.data[0].clauseType,
                    referenceMoney: selData.data[0].referenceMoney,
                    disposeForm: selData.data[0].disposeForm,
                    disposeFormName: febs.getDictLabel(disposeFormList,selData.data[0].disposeForm),
                    examineScore: selData.data[0].examineScore,
                    executeDate: selData.data[0].executeDate,
                    clauseName: clauseName,

                }
                if (null != selectList && valueExists(selectList, "clauseRuleId", returnData.clauseRuleId)) {
                    returnData = null
                }
            }
            return returnData
        }

        $(window).resize(function () {
            initTable();
            commonJS.autoOpenPageHeight($view);
        });

        function valueExists(arrayList, fieldName, value) {
            let result = $.grep(arrayList, function (e) {
                return e[fieldName] == value;
            })
            return result && result.length > 0;
        }
    })
</script>